﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Fall.Core.UnitOfWorks;
using Fall.EntityFrameworkCore.UnitOfWorks;

namespace Fall.EntityFrameworkCore
{
    /// <summary>
    /// 扩展服务
    /// </summary>
    public static class FallEntityFrameworkExtensions
    {
        /// <summary>
        /// 添加工作单元
        /// </summary>
        /// <typeparam name="TDbContext"></typeparam>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddUnitOfWork<TDbContext>(this IServiceCollection services, IConfiguration configuration)
            where TDbContext : DbContext
        {
            return services.AddScoped(typeof(IUnitOfWork<TDbContext>), typeof(UnitOfWork<TDbContext>)).AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork<TDbContext>));
        }
    }
}
